package com.opcode.costa.ui.menu.addorder;

import java.lang.ref.WeakReference;
import android.os.Bundle;
import android.os.Messenger;
import android.support.v4.app.Fragment;
import com.opcode.costa.R;
import com.opcode.nebulamobil.base.activities.MultiFragmentActivityBase;
import com.opcode.nebulamobil.base.components.steptracking.PipelineManager;
import com.opcode.nebulamobil.base.components.steptracking.PipelineStep;
import com.opcode.nebulamobil.base.fragments.FragmentBase;
import com.opcode.nebulamobil.utility.ObjectCreator;

/**
 * Bu aktivite yeni sipariş eklemek ve hesap almak için kullanılacaktır.
 * @author Okan ERDOĞAN
 * 16 Haz 2014
 */
public class AddOrderActivity extends MultiFragmentActivityBase{

	private PipelineManager pipelineManager;	
	
	public AddOrderActivity(){
		
	}
	 protected void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState); 	
		 setContentView(R.layout.new_order_activity_layout); 
		 
		 pipelineManager=new PipelineManager("Siparis Ekle",2);
		 this.pipelineManager.setContainerViewId(R.id.pipeline_container);
		 this.pipelineManager.setStep(new PipelineStep(AddOrderStepOneFragment.class, 0));
		 this.pipelineManager.setStep(new PipelineStep(AddOrderStepTwoFragment.class, 1));
		 super.pipelineForward(pipelineManager, (FragmentBase)ObjectCreator.createClass(AddOrderStepOneFragment.class));
	 } 
	 
	 
	 public void onStart(){
		 super.onStart();
	 }
	 
	 public void onBackPressed(){	 
		 /*
		  * Burada pipelinemanager içerisindeki active step'in NewOrderStepOneFragment olup olmadığına bakılıyor.
		  */
		 if(pipelineManager.getActiveStep()!=null&&pipelineManager.getActiveStep().equals(this.pipelineManager.getStepList().get(0))){
			 System.out.println("AddOrderStepOneFragment");
			 WeakReference<Fragment> fr = pipelineManager.getActiveStep().getwFrag();
			 
			 if(fr != null){
					
			if(((AddOrderStepOneFragment)fr.get()).backPressed())
				return;
			}
			 
		 }else{
			 System.out.println("AddOrderStepTwoFragment");
			 WeakReference<Fragment> fr = pipelineManager.getActiveStep().getwFrag();
			 
			 if(fr != null){
				 
				 if(((AddOrderStepTwoFragment)fr.get()).backPressed()){
					 System.out.println("AddOrderStepTwoFragment1");				 
				 }else{
					 System.out.println("AddOrderStepTwoFragment2");
					 return;

				 }
			}
		 }
		 super.onBackPressed();
	 }
}
